<script type="text/javascript">
	$(document).ready(function() {
		var divId = "${divId!}"; 							//分页显示div
		var formId = "${formId!}"; 							//分页formId
		var splitPageDiv = "${splitPageDiv!}"; 				//分页输出显示的div
		
		if(!divId){  //如果divId为空  则默认值为content
			divId="content"; 
		}
		if(!splitPageDiv){  //如果splitPageDiv为空  则默认值为splitPageDiv
			splitPageDiv="splitPageDiv";
		}
		
		var totalRow = ${splitPage.totalRow!};			//总行数
		var pageSize = ${splitPage.pageSize!};			//每页显示多少条
		var pageNumber = ${splitPage.pageNumber!};		//当前第几页 
		var totalPages = ${splitPage.totalPage!};		//总页数 

		var isSelectPage = true;							// 是否显示第几页     zhengsk 暂时没用
		var isSelectSize = true;							// 是否显示每页显示多少条     zhengsk暂时没用
		
		var orderColunm = "${splitPage.orderColunm!}"; 		//表格排序的列
		var orderMode = "${splitPage.orderMode!}";			//排序的方式

		// 获取分页HTML信息
		var splitStr = generatePageHtml(divId, formId, totalRow, pageSize, pageNumber, totalPages, orderColunm, orderMode);
		
		// 显示分页信息
		$("#" + splitPageDiv).html(splitStr);
	});
	
	
	/**
	 * 生成分分页链接HTML
	 * @param divId
	 * @param formId
	 * @param totalRow
	 * @param pageSize
	 * @param pageNumber
	 * @param totalPages
	 * @param orderColunm
	 * @param orderMode
	 * @returns {String}
	 */
	function  generatePageHtml(divId, formId, totalRow, pageSize, pageNumber, totalPages, orderColunm, orderMode){
		var previousPage = (_locale=="en_US" ) ?  "previous" : "上一页";
		var nextPage = (_locale=="en_US" ) ?  "next" :  "下一页";
		var noData = (_locale=="en_US" ) ?  "no record list !" :  "没有找到符合条件的记录";
		var pageHtml="";
		if(totalRow>0){ //如果行数>0 则显示分页html
			pageHtml +=  '<div class="row m-b-md">';
			if(_locale=="en_US" ){
				pageHtml +=  '<div class="col-md-5">total <b class="allPager fontColor333">' + totalPages + '</b> page&nbsp;&nbsp;skip to &nbsp;<input type="text" id="goPageNumber" class="width30px">&nbsp;page';
			}else{
				pageHtml +=  '<div class="col-md-5">总共 <b class="allPager fontColor333">' + totalPages + '</b> 页&nbsp;&nbsp;跳至 &nbsp;<input type="text" id="goPageNumber" class="width30px">&nbsp;页';
			}
			
			pageHtml +=  '<a class="btn_pagerSearch"  href="#" onclick="goPageLink(\''+divId+'\', \''+formId + '\',' + totalPages +');">&nbsp;GO</a></div>';
			pageHtml +=  '<div class="col-md-7 pull-right">';
			pageHtml +=  '<nav>';
			pageHtml +=  '<ul class="pagination">';
			//console.log("====pageNumber:===="+pageNumber);
			if(pageNumber==1){ //如果当前页码=1.则上一页不可点击，增加样式 class="disabled"
				pageHtml +=  '<li class="disabled"><a href="javascript:void(0)" aria-label="Previous"><span aria-hidden="true">'+previousPage+'</span></a></li>';
			}else{
				pageHtml +=  '<li><a href="#" onclick="splitPageLink(\''+divId+'\', \''+formId+'\', ' + (pageNumber-1) + ');" aria-label="Previous"><span aria-hidden="true">'+previousPage+'</span></a></li>';
			}
			
			//循环遍历页码，拼装html
			for(var i = 1; i <= totalPages; i++){
		        if (i == 2 && pageNumber - 4 > 1) {
		        	pageHtml += '<li><a href="javascript:void(0)">...</a></li>';
		            i = pageNumber - 4;
		        } else if (i == pageNumber + 4 && pageNumber + 4 < totalPages) {
		        	pageHtml += '<li><a href="javascript:void(0)">...</a></li>';
		            i = totalPages - 1;
		        } else {
					if(pageNumber==i){//当前页 增加样式class="active" 
						//pageHtml += '<li class="active"><a href="javascript:splitPageLink(\''+divId+'\', \''+formId+'\', ' + i + ');">' + i + '</a></li>';
						pageHtml += '<li class="active"><a href="#" onclick="splitPageLink(\''+divId+'\', \''+formId+'\', ' + i + ');">' + i + '</a></li>';
					}else{
						pageHtml += '<li><a href="#" onclick="splitPageLink(\''+divId+'\', \''+formId+'\', ' + i + ');">' + i + '</a></li>';
					}
		        }
			}
			
			if(pageNumber==totalPages){ //如果当前页码=最后一页.则下一页不可点击，增加样式 class="disabled"
				pageHtml +=  '<li class="disabled"><a href="javascript:void(0)" aria-label="last"><span aria-hidden="true">'+nextPage+'</span></a></li>';
			}else{
				pageHtml +=  '<li><a href="#" onclick="splitPageLink(\''+divId+'\', \''+formId+'\', ' + (pageNumber+1) + ');" aria-label="last"><span aria-hidden="true">'+nextPage+'</span></a></li>';
			}			
			
			pageHtml +=  '</ul>';
			pageHtml +=  '</nav>';
			pageHtml +=  '</div></div>';
		}else{//如果行数<0   无数据
			console.log("totalRow<0,没有数据");
			var noDataHtml='<tr><td valign="top" colspan="15" style="background:#fff">'+noData+'</td></tr>';
			$('#dataTable').find('tbody').html(noDataHtml);
		}
		//console.log("===pageHtml:"+pageHtml);
		return pageHtml;
	}
	
	
	
	/**
	 * 分页链接处理
	 * @param divId
	 * @param formId
	 * @param toPage
	 */
	function splitPageLink(divId, formId, toPage){
		//在formId中增加 <input type="hidden" name="pageNumber" value=toPage />
		var input = document.createElement('input');
		input.type ='hidden';
		input.name = 'pageNumber';
		input.value = toPage;
		document.getElementById(formId).appendChild(input );
		//console.log("form html:" + $("#"+formId).html());
		ajaxForm(divId, formId);
	}
	
	
	/**
	 * 直接跳转到某一页
	 * @param divId
	 * @param formId
	 * @param totalPages
	 */
	function goPageLink(divId, formId,totalPages){
		var toPage = $("#goPageNumber").val();
		if(!isNaN(toPage)){ //如果toPage是数字，则执行分页函数
			if(toPage>=1&&toPage<=totalPages){
				splitPageLink(divId, formId, toPage);
			}else{
				console.log("==toPage is invalid===");
			}
			
		}
		
	}
</script>

